package com.n9.product.dao;

import com.n9.base.dao.BaseRepository;
import com.n9.product.entity.ReserveRecord;
import com.n9.product.entity.ReserveStatus;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.List;

/**
 * @author ice
 * @since 2019/6/5 16:31
 */
@Repository
public interface ReserveRecordDao extends BaseRepository<ReserveRecord, String> {
    /**
     * 根据专利和状态查询
     * @param patentId
     * @param status
     * @return
     */
    @Query("FROM ReserveRecord WHERE patent.id=:patentId AND status = :status")
    List<ReserveRecord> findByPatentAndStatus(@Param("patentId") String patentId, @Param("status") ReserveStatus status);

    /**
     * 根据专利删除
     * @param id
     */
    @Modifying
    @Query("DELETE ReserveRecord WHERE patent.id = :patentId")
    void deleteByPatent(@Param("patentId") String id);

    /**
     * 查询已过期预留记录
     * @param status
     * @param date
     * @return
     */
    @Query("FROM ReserveRecord WHERE status = :status AND expireDate <= :date")
    List<ReserveRecord> findExpiredByStatus(@Param("status") ReserveStatus status, @Param("date") Date date);
}
